#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000009
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
//bigmod
int bigmod(int b,int p){
if(p==0)return 1;
if(p==1)return b;
int a=bigmod(b,p/2);
a*=a;
a%=MOD;
if(p%2==1)a*=b;
a%=MOD;
return a;
}
//fibonacci sequence
int fib[1];
void fib_init(){
fib[1]=fib[2]=1;
for(int i=3;i<=300005;i++){
fib[i]=fib[i-1]+fib[i-2];
fib[i]%=MOD;
}
}
int sumfib(int a,int b){
int fsum=fib[b+2]-1;
int ssum=fib[a+1]-1;
int ans=fsum-ssum;
ans%=MOD;
return ans;
}
//segment tree with lazy
struct segtree{
struct node{
int max=0;
};
struct lazynode{
int sum=0;
};
vector<node> tree;
vector<lazynode> lazy;
vector<int> arr;
int n;
void build(int ind, int l, int r){
if(l==r){
tree[ind].max=arr[l];
lazy[ind].sum=0;
return;
}
int mid =l+(r-l)/2;
build(ind*2,l,mid);
build(ind*2+1,mid+1,r);
tree[ind].max=max(tree[ind*2].max,tree[ind*2+1].max);
lazy[ind].sum=0;
return;
}
segtree(vector<int>& a) : n(a.size()) {
int SIZE = n;
tree.resize(4 * SIZE );
lazy.resize(4 * SIZE );
arr=a;
build(1, 0, n-1);
}
void update(int ind,int l,int r, int li,int ri,int x){
int mid=l+(r-l)/2;
if(li>r||ri<l)return;
if(l==r){
tree[ind].max+=lazy[ind].sum+x;
lazy[ind].sum=0;
}
if(lazy[ind].sum!=0){
tree[ind].max+=lazy[ind].sum;
lazy[ind*2].sum+=lazy[ind].sum;
lazy[ind*2+1].sum+=lazy[ind].sum;
lazy[ind].sum=0;
}
if(li<=l&&r<=ri){
tree[ind].max+=x;
lazy[ind*2+1].sum+=x;
lazy[ind*2].sum+=x;
return;
}
update(ind*2,l,mid,li,ri,x);
update(ind*2+1,mid+1,r,li,ri,x);
tree[ind].max=max(tree[ind*2].max,tree[ind*2+1].max);
return;
}
node query(int ind,int l,int r, int li,int ri){
node nul;
nul.max=INT_MIN;
int mid=l+(r-l)/2;
if(li>r||ri<l){
return nul;
}
if(l==r){
tree[ind].max+=lazy[ind].sum;
lazy[ind].sum=0;
return tree[ind];
}
if(lazy[ind].sum!=0){
tree[ind].max+=lazy[ind].sum;
lazy[ind*2].sum+=lazy[ind].sum;
lazy[ind*2+1].sum+=lazy[ind].sum;
lazy[ind].sum=0;
}
if(li<=l&&r<=ri){
return tree[ind];
}
node a1=query(ind*2,l,mid,li,ri);
node a2=query(ind*2+1,mid+1,r,li,ri);
a1.max=max(a1.max,a2.max);
return a1;
}
void update(int li,int ri,int x){
update(1,0,n-1,li,ri,x);
}
int query(int li,int ri){
return query(1,0,n-1,li,ri).max;
}
};
//merge sort tree
struct mstree{
struct node{
vector<int> nums;
};
vector<node> tree;
vector<int> arr;
int n;
void build(int ind, int l, int r){
if(l==r){
tree[ind].nums={arr[l]};
return;
}
int mid =l+(r-l)/2;
build(ind*2,l,mid);
build(ind*2+1,mid+1,r);
merge(tree[2*ind].nums.begin(),tree[2*ind].nums.end(),tree[2*ind+1].nums.begin(),tree[2*ind+1].nums.end(),back_inserter(tree[ind].nums));
return;
}
mstree(vector<int>& a) : n(a.size()) {
int SIZE = n;
tree.resize(4 * SIZE );
arr=a;
build(1, 0, n-1);
}
int query(int ind,int l,int r,int li,int ri,int ml,int mr){
int mid=l+(r-l)/2;
if(li>r||ri<l){
return 0;
}
if(li<=l&&r<=ri){
return lower_bound(tree[ind].nums.begin(),tree[ind].nums.end(),mr)-lower_bound(tree[ind].nums.begin(),tree[ind].nums.end(),ml);
}
int a1=query(ind*2,l,mid,li,ri,ml,mr);
int a2=query(ind*2+1,mid+1,r,li,ri,ml,mr);
return a1+a2;
}
int query(int l,int r,int ml,int mr){
return query(1,0,n-1,l,r,ml,mr);
}
};
vector<int> adj[10];
int dfs(int a,int prev){
for(int i=0;i<adj[a].size();i++){
if(adj[a][i]!=prev)dfs(a,i);
}
return 0;
}
void solve(){
int n;
cin>>n;
int arr[n][n];
for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>arr[i][j];
int fin[n];
for(int i=0;i<n;i++)fin[i]=0;
bool contr=0;
for(int bit=1;bit<1073741824;bit*=2){
int cur[n][n];
for(int i=0;i<n;i++)for(int j=0;j<n;j++)cur[i][j]=(arr[i][j]&bit);
int ans[n];
for(int i=0;i<n;i++)ans[i]=1;
for(int i=0;i<n;i++)for(int j=0;j<n;j++){
if(i==j)continue;
if(cur[i][j]==0)ans[i]=0,ans[j]=0;
}
for(int i=0;i<n;i++)for(int j=0;j<n;j++){
if(i==j)continue;
if(cur[i][j]>=1&&ans[i]==0&&ans[j]==0){
cout<<"NO\n";
return;
}
}
// cout<<'\n';
for(int i=0;i<n;i++)fin[i]+=ans[i]*bit;
}
cout<<"YES\n";
for(int i=0;i<n;i++)cout<<fin[i]<<' ';
cout<<'\n';
return;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)solve();
}
1475B - New Year's Number | 461A - Appleman and Toastman |
320B - Ping-Pong (Easy Version) | 948A - Protect Sheep |
387A - George and Sleep | 53A - Autocomplete |
1729G - Cut Substrings | 805B - 3-palindrome |
805C - Find Amir | 676C - Vasya and String |
1042B - Vitamins | 1729F - Kirei and the Linear Function |
25D - Roads not only in Berland | 1694A - Creep |
659F - Polycarp and Hay | 1040A - Palindrome Dance |
372A - Counting Kangaroos is Fun | 1396B - Stoned Game |
16A - Flag | 1056A - Determine Line |
670B - Game of Robots | 1418C - Mortal Kombat Tower |
1382B - Sequential Nim | 1272C - Yet Another Broken Keyboard |
808A - Lucky Year | 1245A - Good ol' Numbers Coloring |
58B - Coins | 1041C - Coffee Break |
507A - Amr and Music | 1041D - Glider |